package cn.iocoder.yudao.module.design.dal.mysql.purchase;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.design.controller.admin.purchase.vo.PurchaseExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.purchase.vo.PurchasePageReqVO;
import cn.iocoder.yudao.module.design.dal.dataobject.purchase.PurchaseDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 采购清单 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseMapper extends BaseMapperX<PurchaseDO> {

    default PageResult<PurchaseDO> selectPage(PurchasePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseDO>()
                .eqIfPresent(PurchaseDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(PurchaseDO::getFlowId, reqVO.getFlowId())
                .likeIfPresent(PurchaseDO::getName, reqVO.getName())
                .likeIfPresent(PurchaseDO::getPersonName, reqVO.getPersonName())
                .eqIfPresent(PurchaseDO::getMobile, reqVO.getMobile())
                .eqIfPresent(PurchaseDO::getCnt, reqVO.getCnt())
                .eqIfPresent(PurchaseDO::getSize, reqVO.getSize())
                .eqIfPresent(PurchaseDO::getPlace, reqVO.getPlace())
                .betweenIfPresent(PurchaseDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseDO::getId));
    }

    default List<PurchaseDO> selectList(PurchaseExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PurchaseDO>()
                .eqIfPresent(PurchaseDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(PurchaseDO::getFlowId, reqVO.getFlowId())
                .likeIfPresent(PurchaseDO::getName, reqVO.getName())
                .likeIfPresent(PurchaseDO::getPersonName, reqVO.getPersonName())
                .eqIfPresent(PurchaseDO::getMobile, reqVO.getMobile())
                .eqIfPresent(PurchaseDO::getCnt, reqVO.getCnt())
                .eqIfPresent(PurchaseDO::getSize, reqVO.getSize())
                .eqIfPresent(PurchaseDO::getPlace, reqVO.getPlace())
                .betweenIfPresent(PurchaseDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseDO::getId));
    }
    List<Map>  getPurchaseListByFlowId(@Param("flowId") Long flowId, @Param("statusCd")String statusCd);
}
